thin.imports('/public/home/css/register.css');

thin.imports('/public/home/resource/compress.js');

thin.use(function() {
	// 路由
	checkLocation();

	$('#btn-checkaccess').on('click', function(e) {
		var act = $(this).data('action');
		if(act == 'register') {
			verifySMSCode(function() {
				$.hideLoading();
				checkLocation('viden');
			});
		} else if(act == 'bind') {
			verifySMSCode(wxbind);
		}
	});

	// 绑定压缩上传图片按钮
	$('[layout-mark=uploadFile]').on('change', thin.uploadImage);

	var scene = tool.getSearch('scene');
	if(scene && scene == 'edit') $('[layout-mark=backbtn]').css('display', 'block');
});

var __getdata_wxbind;

function __complete_wxbind(res) {
	$.hideLoading();
	if(res.status == 201) {
		$.toast("操作成功", 960);
		setTimeout(function() {
			window.location.href = '/mobile/service/member';
		}, 800);
	} else {
		$.toptip(res.error, 'error');
	}
}

function wxbind() {
	__getdata_wxbind = {
		'mobile': $('[layout-mark=sms-mobile]').val()
	};
	thin.imports('/public/configure/conf.complete.js', function() {
		factory.request('_reg_wxbind');
	});
}

var jude_vphone = false,
	jude_viden = false,
	jude_org = false,
	jude_minfo = false,
	jude_mlike = false;

function checkLocationCallback(hash) {
	if(hash == 'vphone') {
		if(!jude_vphone) {
			$.showLoading();
			thin.imports('/public/home/resource/sms.js', function() {
				$.hideLoading();
			});
			jude_vphone = true;
		}
	}

	if(hash == 'viden') {
		if(!jude_viden) {
			$.showLoading();
			thin.imports('/public/home/resource/cmp-register.js', function() {
				$.hideLoading();
			});
			jude_viden = true;
		}
	}

	if(hash == 'mechanism' || hash == 'mlist') {
		if(!jude_org) {
			$.showLoading();
			thin.imports('/public/home/resource/cmp-org.js', function() {
				$.hideLoading();
			});
			jude_org = true;
		}
	}

	if(hash == 'memberinfo') {
		if(!jude_minfo) {
			$.showLoading();
			//$('#ipt-mobile').val($('[name=mobile]').val());
			thin.imports('/public/home/resource/cmp-minfo.js', function() {
				$.hideLoading();
			});
			jude_minfo = true;
		}
	}

	if(hash == 'memberlike') {
		if(!jude_mlike) {
			$.showLoading();
			thin.imports('/public/home/resource/cmp-mlike.js', function() {
				$.hideLoading();
			});
			jude_mlike = true;
		}
	}
}